package team.nmsg.photo.util;

import org.apache.commons.codec.digest.DigestUtils;

import com.alibaba.fastjson.JSONObject;

import team.nmsg.ge.system.interf.ISysBean;

public class JSApiSignature implements ISysBean{
	
	private String noncestr = "photoliveabcdefg";
	private Long timestamp= System.currentTimeMillis() / 1000; //s
	
	private String jsapi_ticket;
	private String url;
	
	private String signature;
	
	public JSApiSignature() {
		
	}
	
	public JSApiSignature(String jsapi_ticket, String url) {
		this.jsapi_ticket = jsapi_ticket;
		this.url = url;
	}


	public JSONObject doSignature() {
		
//		timestamp = timestamp / 1000;
		String aaa = "jsapi_ticket="+jsapi_ticket + "&noncestr=" + noncestr + "&timestamp=" +timestamp + "&url="  + url;
		
		
//		System.out.println(  aaa  );
		signature = DigestUtils.sha1Hex(aaa);
		
		JSONObject json = (JSONObject) JSONObject.toJSON(this);
		
		json.put("appID", WxUtil.wx_appID );
		
		return json;
	}
	
	@Override
	public JSONObject toJson() {
		
		JSONObject json = (JSONObject) JSONObject.toJSON(this);
		
		
		return json;
	}

	public String getNoncestr() {
		return noncestr;
	}

	public void setNoncestr(String noncestr) {
		this.noncestr = noncestr;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public String getJsapi_ticket() {
		return jsapi_ticket;
	}

	public void setJsapi_ticket(String jsapi_ticket) {
		this.jsapi_ticket = jsapi_ticket;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getSignature() {
		return signature;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}
	
	
}
